package com.lbj.yuanxi.yx000

import android.annotation.SuppressLint
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.lbj.yuanxi.R
import com.lbj.yuanxi.yx001.FloatingWindowActivity

class MainAdapter(private val context: Context) : BaseAdapter() {

    private var mList = arrayListOf<Pair<String, Class<out Activity>>>()
    private var inflater: LayoutInflater

    init {
        mList.add(Pair("360加速球核心效果实现", FloatingWindowActivity::class.java))
        inflater = LayoutInflater.from(context)
    }

    override fun getCount() = mList.size

    override fun getItem(position: Int) = mList[position]

    override fun getItemId(position: Int) = position.toLong()

    @SuppressLint("ViewHolder")
    override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
        val pair = mList[position]
        val rootView = inflater.inflate(R.layout.yx000_adapter_main, parent, false)
        val tvTitle = rootView.findViewById<TextView>(R.id.tvTitle)
        tvTitle.text = pair.first
        tvTitle.setOnClickListener {
            val intent = Intent(context, pair.second)
            context.startActivity(intent)
        }
        return rootView
    }
}